class Solution
{
public:
    int countBalls(int lowLimit, int highLimit)
    {
        unordered_map<int, int> boxCount;
        auto digitSum = [](int x)
        {
            int result = 0;
            while (x)
            {
                result += x % 10;
                x /= 10;
            }
            return result;
        };
        for (int i = lowLimit; i <= highLimit; ++i)
        {
            ++boxCount[digitSum(i)];
        }
        int maxCount = boxCount.begin()->second;
        for (auto &[box, count] : boxCount)
        {
            if (count > maxCount)
            {
                maxCount = count;
            }
        }
        return maxCount;
    }
};